package com.orphan.limitedDeal.service.impl;

import com.orphan.limitedDeal.dao.GoodsReturnMapper;
import com.orphan.limitedDeal.dao.PromotionMapper;
import com.orphan.limitedDeal.po.GoodsReturn;
import com.orphan.limitedDeal.po.PromotionGoodss;
import com.orphan.limitedDeal.service.PromotionServices;
import com.orphan.util.dto.GoodsDto;
import com.orphan.util.dto.PromotionGoodsDto;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("PromotionServiceImpl")
public class PromotionServiceImpl implements PromotionServices {
    @Autowired
    PromotionMapper promotionMapper;
    @Autowired
    GoodsReturnMapper goodsReturnMapper;
    @RabbitListener(queues = "queueGoosUpShow")
    public void getGoodsList(GoodsDto goodsDto){
        GoodsReturn goodsReturn = new GoodsReturn();
        goodsReturn.setGoodsInfo(goodsDto.getGoodSize());
        goodsReturn.setGoodsName(goodsDto.getGoodName());
        goodsReturn.setGoodsNum(goodsDto.getGoodNum());
        goodsReturn.setGoodsPrice(Integer.parseInt(goodsDto.getGoodPrice()));
        goodsReturn.setGoodsType(goodsDto.getGoodType());
        goodsReturn.setGoodsPic("小米10.png");
        goodsReturn.setGoodsTag(goodsDto.getGoodTag());

        GoodsReturn goodsReturn1 = goodsReturnMapper.selectGoods(goodsReturn);
        if(goodsReturn1 == null){
            goodsReturnMapper.addGoods(goodsReturn);
        }else{
            goodsReturnMapper.updateGoods(goodsReturn);
        }


        System.out.println(goodsDto+"");
    }
//    @RabbitListener(queues = "queueProm")
//    public void getGoodsList(PromotionGoodsDto promotionGoodsDto){
//        System.out.println(promotionGoodsDto+"");
//    }

    @Override
    public List<PromotionGoodss> selectAll() {
        return promotionMapper.selectAll();
    }

    @Override
    public List<PromotionGoodss> selectPromotion() {
        return promotionMapper.selectPromotion();
    }

    @Override
    public List<PromotionGoodss> selectGoodsName(String goodsName) {
        return promotionMapper.selectGoodsName(goodsName);
    }

    @Override
    public boolean updateGoods(PromotionGoodss promotionGoodss) {
        int i=promotionMapper.updateGoods(promotionGoodss);
        if (i>0) {
            return true;
        }else {
            return false;
        }
    }

    @Override
    public boolean setTag(PromotionGoodss promotionGoodss) {
        int i=promotionMapper.setTag(promotionGoodss);
        if (i>0) {
            return true;
        }else {
            return false;
        }
    }
}
